﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GeneralUtilities;
using GLiteInterfaces;
using GanagroLiteBO;

namespace GanagroLite
{
    public partial class CambiarLote : GanagroLite.WinPart //, IOperacionView
    {
        public CambiarLote()
        {
            InitializeComponent();
            this.bindingSourceGanado.DataSource = new BindingList<GanagroLiteBO.GANADO_BO>();
        }

        protected internal override object GetIdValue()
        {
            return "Cambiar Lote";
        }

        public override string ToString()
        {
            return string.Format("Cambiar de lote");
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            this.bindingSourceLotes.DataSource = UtilityDB.Loadlotes();
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.ComboBoxLote.DataSource = bindingSourceLotes;

        }

        private void CambiarLote_Load(object sender, EventArgs e)
        {
            this.ComboBoxLote.ValueMember = "ID";
            this.ComboBoxLote.DisplayMember = "DESCRIPCION";

            this.backgroundWorker1.WorkerReportsProgress = false;
            this.backgroundWorker1.RunWorkerAsync();
        }

        private void buttonSalir_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Esta seguro que desea salir?", "Confirmar", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                this.bindingSourceLotes.CancelEdit();
                this.Close();
            }
        }

        private void buttonAceptar_Click(object sender, EventArgs e)
        {
            BindingList<GANADO_BO> Semovientes = ((BindingList<GanagroLiteBO.GANADO_BO>)bindingSourceGanado.DataSource);
            byte loteId = Convert.ToByte(ComboBoxLote.SelectedValue);

            GanagroLiteBO.utilities.CambiarGanadodeLoteYRegistrarOperacion(Semovientes, loteId, dateTimePicker1.Value);

            Semovientes.Clear();

        }

        private void bindingSourceGanado_AddingNew(object sender, AddingNewEventArgs e)
        {
            BindingList<GANADO_BO> Semovientes = ((BindingList<GanagroLiteBO.GANADO_BO>)bindingSourceGanado.DataSource);
            List<string> nuevoscodigos = (from p in Semovientes select p.CODIGO).ToList<string>();
            e.NewObject = new GanagroLiteBO.GANADO_BO(nuevoscodigos);
//            e.NewObject = new GanagroLiteBO.GANADO_BO();
        }

    }
}
